package com.cloudlead.web.resource;
import org.springframework.stereotype.Controller;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
@Controller
@Path("/test")
@Produces(MediaType.APPLICATION_JSON)
public class ImportCarInfo {
    @Context
    private HttpServletRequest request;
    @Context
    HttpServletResponse response;
    @GET
    @Path("/list")
    public Response downloadFile(@QueryParam("key") String key) {
        ClientData clientDate = new ClientData();
        List<Map> listEnd = new ArrayList<Map>();
        Map map = new HashMap();
        map.put("id", "123");
        map.put("name", "杨鑫");
        listEnd.add(map);
        clientDate.setRows(listEnd);
        UtilExcel ut = new UtilExcel();
        InputStream inp = null;
        try {
            inp = ut.ExportToExcel(clientDate,"船公司,id,140#车队名,name,140",response);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return Response.ok(MediaType.TEXT_XML_TYPE).header("Content-Disposition", "attachment;filename=" + "testA.XLS").
                entity(inp).build();

    }

}
